Micron Document
Livres et Wikis | Archives | Info


C++ Standard Library
layout: Wide · Narrow · Centered
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
top
In the C++ programming language, the C++ Standard Library is a collection of classes and functions, which are written in the core language and part of the C++ ISO Standard itself.cite-ref-1[1]

Contents

• Overview
• Discontinued
• See also
• General
• Containers
• Localisation
• Strings
• See also
• References

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Overview

The C++ Standard Library provides several generic containers, functions to use and manipulate these containers, function objects, generic strings and streams (including interactive and file I/O), support for some language features, and functions for common tasks such as finding the square root of a number. The C++ Standard Library also incorporates most headers of the ISO C standard library ending with ".h", but their use was deprecated (reverted the deprecation since C++23cite-ref-2[2]).cite-ref-3[3] C++23 instead considers these headers as useful for interoperability with C, and recommends against their usage outside of programs that are intended to be both valid C and C++ programs. No other headers in the C++ Standard Library end in ".h". Features of the C++ Standard Library are declared within the std namespace.

The C++ Standard Library is based upon conventions introduced by the Standard Template Library (STL), and has been influenced by research in generic programming and developers of the STL such as Alexander Stepanov and Meng Lee.cite-ref-4[4]cite-ref-5[5] Although the C++ Standard Library and the STL share many features, neither is a strict superset of the other. The design of the C++ standard library, much like the C standard library, is minimalistic, and contains only core features for programming, lacking most of the more specialised features offered by the Java standard library or C# standard library. For more features, some third-party libraries such as Boost libraries and POCO C++ Libraries, which offer additional features, may be used to supplement the standard library.

A noteworthy feature of the C++ Standard Library is that it not only specifies the syntax and semantics of generic algorithms, but also places requirements on their performance.cite-ref-6[6] These performance requirements often correspond to a well-known algorithm, which is expected but not required to be used. In most cases this requires linear time O(n) or linearithmic time O(n log n), but in some cases higher bounds are allowed, such as quasilinear time O(n log2 n) for stable sort (to allow in-place merge sort). Previously, sorting was only required to take O(n log n) on average, allowing the use of quicksort, which is fast in practice but has poor worst-case performance, but introsort was introduced to allow both fast average performance and optimal worst-case complexity, and as of C++11, sorting is guaranteed to be at worst linearithmic. In other cases requirements remain laxer, such as selection, which is only required to be linear on average (as in quickselect),cite-ref-7[7] not requiring worst-case linear as in introselect.

The C++ Standard Library underwent ISO standardization as part of the C++ ISO Standardization effort in the 1990s. Since 2011, it has been expanded and updated every three yearscite-ref-8[8] with each revision of the C++ standard.

Since C++23, the C++ Standard Library can be imported using modules, which were introduced in C++20.

Implementations

| Name | Organization |
|---|---|
| GNU C++ Standard Library | GNU Project and Free Software Foundation |
| LLVM C++ Standard Library | LLVM Developer Group |
| NVIDIA C++ Standard Library | Nvidia |
| Microsoft C++ Standard Library | Microsoft |
| HPX C++ Standard Library for Parallelis… | STELLAR Group |
| Electronic Arts Standard Template Libra… | Electronic Arts |
| Dinkum C++ Library | Dinkumware |
| Cray C++ Standard Library | Cray User Group |

| Name | Homepage | Acronym |
|---|---|---|
| GNU C++ Standard Library | | libstdc++ |
| LLVM C++ Standard Library | | libc++ |
| NVIDIA C++ Standard Library | | libcudacxx |
| Microsoft C++ Standard Library | | MSVC STL |
| HPX C++ Standard Library for Parallelis… | | HPX |
| Electronic Arts Standard Template Libra… | | EASTL |
| Dinkum C++ Library | Archived 11 February 2021 at the Waybac… | Unknown |
| Cray C++ Standard Library | | Unknown |

| Name | Licence |
|---|---|
| GNU C++ Standard Library | GPLv3 with GCC Runtime Library Exception |
| LLVM C++ Standard Library | Apache License 2.0 with LLVM Exceptions |
| NVIDIA C++ Standard Library | Apache License 2.0 with LLVM Exceptions |
| Microsoft C++ Standard Library | Apache License 2.0 with LLVM Exceptions |
| HPX C++ Standard Library for Parallelis… | Boost Software License 1.0 |
| Electronic Arts Standard Template Libra… | BSD 3-Clause License |
| Dinkum C++ Library | Commercial |
| Cray C++ Standard Library | Commercial |

| Name | Latest release |
|---|---|
| GNU C++ Standard Library | New major release once per year |
| LLVM C++ Standard Library | Every 2 weeks |
| NVIDIA C++ Standard Library | September 4, 2024 ( 2024-09-04 ) |
| Microsoft C++ Standard Library | Daily |
| HPX C++ Standard Library for Parallelis… | May 29, 2024 ( 2024-05-29 ) |
| Electronic Arts Standard Template Libra… | August 31, 2024 ( 2024-08-31 ) |
| Dinkum C++ Library | Unknown |
| Cray C++ Standard Library | Unknown |

Discontinued

Apache C++ Standard Library

The Apache C++ Standard Library is another open-source implementation. It was originally developed commercially by Rogue Wave Software and later donated to the Apache Software Foundation.cite-ref-9[9] However, after more than five years without a release, the board of the Apache Software Foundation decided to end this project and move it to Apache Attic.cite-ref-10[10]

See also

The following libraries implement much of the C++ Standard Library:

| Name | Description |
|---|---|
| Abseil | An open source collection of libraries… |
| Folly | A variety of C++14 libraries that are u… |
| Bareflank Support Library | A C++ library where everything can be e… |

Standard modules

Although modules were first introduced in C++20, standard library modules were only standardised as part of the language in C++23. These named modules were added to include all items declared in both global and std namespaces provided by the importable standard headers. Macros are not allowed to be exportable, so users have to manually include or import headers that emit macros for use.

The C++ standard has reserved std and std.* as module names,cite-ref-p2465r3-11-0[11] however most compilers allow a flag to override this.cite-ref-12[12]

The current standard library modules defined by the standard as of C++23 are:

| Name | Description |
|---|---|
| std | Exports all declarations in namespace s… |
| std.compat | Exports the same declarations as the na… |

The above modules export the entire C++ standard library, meaning that as of currently, the standard library must be imported in its entirety. Furthermore, modules do not allow for granular imports of specific namespaces, classes, or symbols within a module, unlike Java or Rust which do allow for the aforementioned. Importing a module imports all symbols marked with export, making it akin to a wildcard import in Java or Rust.

Like Java's packages, C++ modules do not have a hierarchical system, but typically use a hierarchical naming convention. In other words, C++ does not have "submodules", meaning the . symbol which may be included in a module name bears no syntactic meaning and is used only to suggest the association of a module. As an example, std.compat is not a submodule of std, but is named so to indicate the association the module bears to the std module (as a "compatibility" version of it).

It has been proposed that additional modules providing other subsets of the standard library be added, which may eventually be included in a future revision.cite-ref-p0581r1-13-0[13]cite-ref-p2412r0-14-0[14] These include:

| Name | Description |
|---|---|
| std.fundamental | Exports the utility facilities within t… |
| std.core | Exports everything in std.fundamental ,… |
| std.io | Exports facilities for input/output . |
| std.os | Exports facilities for interfacing with… |
| std.concurrency | Exports facilities for concurrent progr… |
| std.math | Exports facilities for mathematics and… |

Standard headers

The following files contain the declarations of the C++ Standard Library.

Legend:
: Deprecated
: Removed

General

Components that C++ programs may use for increased features.

| Name | Description |
|---|---|
| <any> | Added in C++17 . Provides a type-erased… |
| <cerrno> | Related to <errno.h> . For testing erro… |
| <chrono> | Provides time elements, such as std::ch… |
| <concepts> | Added in C++20 . Provides fundamental l… |
| <contracts> | Added in C++26 . Provides design by con… |
| <csetjmp> | Related to <setjmp.h> . Declares the ma… |
| <csignal> | Related to <signal.h> . Defines signal-… |
| <cstdalign> | Related to <stdalign.h> . For querying… |
| <cstdbool> | Related to <stdbool.h> . Defines a Bool… |
| <cstddef> | Related to <stddef.h> . Defines several… |
| <cstdint> | Related to <stdint.h> . Defines exact-w… |
| <ctime> | Related to <time.h> . Defines date- and… |
| <debugging> | Added in C++26 . Provides fundamental l… |
| <expected> | Added in C++23 . Provides class templat… |
| <functional> | Provides several function objects , des… |
| <generator> | Added in C++23 . Provides a coroutine g… |
| <memory> | Provides facilities for memory manageme… |
| <memory_resource> | Added in C++17 . Provides facilities fo… |
| <optional> | Added in C++17 . Provides class templat… |
| <scoped_allocator> | Added in C++11 . Provides std::scoped_a… |
| <stacktrace> | Added in C++23 . Provides stack trace o… |
| <stdexcept> | Contains standard exception classes suc… |
| <system_error> | Added in C++11 . Defines std::error_code |
| <tuple> | Added in C++11 and TR1. Provides a clas… |
| <type_traits> | Added in C++11 . Provides metaprogrammi… |
| <utility> | The utility file provides various utili… |
| <variant> | Added in C++17 . Provides a class templ… |

Language support

Components that C++ programs may use for support during development.

| Name | Description |
|---|---|
| <cassert> | Related to <assert.h> . Declares the as… |
| <cfenv> | Related to <errno.h> . Defines a set of… |
| <cfloat> | Related to <float.h> . Defines macro co… |
| <cinttypes> | Related to <inttypes.h> . Defines exact… |
| <ciso646> | Related to <iso646.h> . Defines several… |
| <climits> | Related to <limits.h> . Defines macro c… |
| <compare> | Added in C++20 . Provides three-way com… |
| <coroutine> | Added in C++20 . Provides coroutine sup… |
| <debugging> | Added in C++26 . Provides debugging sup… |
| <exception> | Provides several types and functions re… |
| <initializer_list> | Added in C++11 . Provides initializer l… |
| <limits> | Provides the class template std::numeri… |
| <meta> | Added in C++26 . Provides reflective pr… |
| <new> | Provides operators new and delete and o… |
| <source_location> | Added in C++20 . Provides capturing sou… |
| <stdfloat> | Added in C++23 . Provides conditional s… |
| <typeinfo> | Provides facilities for working with C+… |
| <version> | Added in C++20 . Provides information a… |

Containers

Components that C++ programs may use for container data structures.

| Name | Description |
|---|---|
| <array> | Added in C++11 and TR1 . Provides the c… |
| <bitset> | Provides the specialized container clas… |
| <deque> | Provides the container class template s… |
| <flat_map> | Added in C++23 . Provides the container… |
| <flat_set> | Added in C++23 . Provides the container… |
| <forward_list> | Added in C++11 and TR1 . Provides the c… |
| <inplace_vector> | Added in C++26 . Provides the class std… |
| <hive> | Added in C++26 . Provides the class std… |
| <map> | Provides the container class templates… |
| <mdspan> | Added in C++23 . Provides the class tem… |
| <queue> | Provides the container adapter class st… |
| <set> | Provides the container class templates… |
| <span> | Added in C++20 . Provides the class tem… |
| <stack> | Provides the container adapter class st… |
| <unordered_map> | Added in C++11 and TR1 . Provides the c… |
| <unordered_set> | Added in C++11 and TR1 . Provides the c… |
| <vector> | Provides the container class template s… |

Iterators and ranges

Components that C++ programs may use to manipulate iterators, ranges, and algorithms over ranges and containers.

| Name | Description |
|---|---|
| <algorithm> | Provides definitions of many algorithms… |
| <execution> | Added in C++17 . Provides execution pol… |
| <iterator> | Provides classes and templates for work… |
| <numeric> | Generalized numeric algorithms. |
| <ranges> | Added in C++20 . Provides ranges facili… |

Localisation

Components that C++ programs may use for localisation and character encoding manipulation.

| Name | Description |
|---|---|
| <clocale> | Related to <locale.h> . Defines localiz… |
| <codecvt> | Provides code conversion facets for var… |
| <locale> | Defines classes and declares functions… |
| <text_encoding> | Added in C++26 . Provides text encoding… |

Strings

Components that C++ programs may use for string manipulation.

| Name | Description |
|---|---|
| <cctype> | Related to <ctype.h> . Defines set of f… |
| <charconv> | Added in C++17 . Provides a locale-inde… |
| <cstring> | Related to <string.h> . Defines string-… |
| <cuchar> | Related to <uchar.h> . Types and functi… |
| <cwchar> | Related to <wchar.h> . Defines wide-str… |
| <cwctype> | Related to <wctype.h> . Defines set of… |
| <format> | Added in C++20 . Provides a modern way… |
| <string> | Provides the C++ standard string classe… |
| <string_view> | Added in C++17 . Provides class templat… |
| <regex> | Added in C++11 . Provides utilities for… |

Streams, files, and input/output

Components that C++ programs may use for input/output manipulation and file manipulation.

| Name | Description |
|---|---|
| <cstdio> | Related to <stdio.h> . Defines core inp… |
| <filesystem> | Added in C++17 . Provides facilities fo… |
| <fstream> | Provides facilities for file-based inpu… |
| <iomanip> | Provides facilities to manipulate outpu… |
| <ios> | Provides several types and functions ba… |
| <iosfwd> | Provides forward declarations of severa… |
| <iostream> | Provides C++ input and output fundament… |
| <istream> | Provides std::istream and other support… |
| <ostream> | Provides std::ostream and other support… |
| <print> | Added in C++23 . Provides formatted out… |
| <spanstream> | Added in C++23 . Provides std::spanstre… |
| <sstream> | Provides std::stringstream and other su… |
| <streambuf> | Provides reading and writing functional… |
| <strstream> | Provides input/output operations on arr… |
| <syncstream> | Added in C++20 . Provides std::osyncstr… |

Thread support library

Components that C++ programs may use for threading and concurrent programming.

| Name | Description |
|---|---|
| <atomic> | Added in C++11 . Provides class templat… |
| <barrier> | Added in C++20 . Provides std::barrier… |
| <cstdarg> | Related to <stdarg.h> . For atomic oper… |
| <future> | Added in C++11 . In 32.9.1-1, this sect… |
| <hazard_pointer> | Added in C++26 . Provides hazard pointe… |
| <latch> | Added in C++20 . Provides std::latch ,… |
| <mutex> | Added in C++11 . In 32.5-1, this sectio… |
| <rcu> | Added in C++26 . Provides read-copy-upd… |
| <shared_mutex> | Added in C++14 . Provides facility for… |
| <semaphore> | Added in C++20 . Provides semaphore tha… |
| <stop_token> | Added in C++20 . In 32.3.1-1, this sect… |
| <thread> | Added in C++11 . Provide class and name… |

Numerics library

Components that C++ programs may use to perform seminumerical or mathematical operations.

| Name | Description |
|---|---|
| <bit> | Added in C++20 . Provides bit manipulat… |
| <ccomplex> | Related to <complex.h> . Defines a set… |
| <cmath> | Related to <math.h> . Defines common ma… |
| <complex> | Defines a class template std::complex ,… |
| <ctgmath> | Related to <tgmath.h> . Defines type-ge… |
| <linalg> | Added in C++26 . Provides linear algebr… |
| <numbers> | Added in C++20 . Provides mathematical… |
| <simd> | Added in C++26 . Provides data-parallel… |
| <random> | Added in C++11 . Facility for generatin… |
| <ratio> | Added in C++11 . Provides compile-time… |
| <valarray> | Defines five class templates ( std::val… |

C standard library

Each header from the C Standard Library is included in the C++ Standard Library under a different name, generated by removing the '.h' file extension, and adding a 'c' at the start; for example, 'time.h' becomes 'ctime'. The only difference between these headers and the traditional C Standard Library headers is that where possible the functions should be placed into the std:: namespace. In ISO C, functions in the standard library are allowed to be implemented by macros, which is not allowed by ISO C++.

Usage of the C headers with the '.h' file extension is legal in C++ and used for compatibility.

The following headers are special C compatibility headers which do not have a corresponding C++ naming convention, meaning that the C headers must be used if the header is necessary.

| Name | Description |
|---|---|
| <stdatomic.h> | Added in C++23 . Related to <stdatomic.… |
| <stdbit.h> | Added in C++26 . Related to <stdatomic.… |
| <stdchkint.h> | Added in C++26 . Related to <stdchkint.… |

The C headers <stdnoreturn.h> and <threads.h> do not have C++ equivalents and their C headers are not supported in C++.

C++ does not provide the C POSIX library as part of any standard, however it is legal to use in a C++ program. If used in C++, the POSIX headers are not prepended with a "c" at the beginning of the name, and all contain the .h suffix in the header name. Most headers in the POSIX library typically have a C++ equivalent implementation, such as <regex> rather than <regex.h>.

See also
References

cite-note-11. ↑ ISO/IEC 14882:2003(E) Programming Languages – C++ §17-27
cite-note-22. ↑ citerefk-ppe2021Köppe, Thomas (11 June 2021). "Clarifying the status of the "C headers"".
cite-note-33. ↑ ISO/IEC 14882:2003(E) Programming Languages – C++ §D.5
cite-note-44. ↑ citerefstroustrup1994Stroustrup, Bjarne (1994). The Design and Evolution of C++ §8.5. Addison Wesley. ISBN 0-201-54330-3.
cite-note-55. ↑ citerefstepanovlee1994Stepanov, Alexander; Lee, Meng (1 August 1994). "The Standard Template Library". HP Labs. Archived from the original on 9 November 1997. Retrieved 22 October 2017.
cite-note-66. ↑ "Generic Algorithms Archived 3 June 2023 at the Wayback Machine", David Musser
cite-note-77. ↑ "std::nth_element". cppreference.com. Archived from the original on 29 March 2018. Retrieved 20 March 2018.
cite-note-88. ↑ "C++ IS Schedule Archived 5 May 2024 at the Wayback Machine", Herb Sutter
cite-note-99. ↑ "Apache C++ Standard Library". Archived from the original on 8 April 2023. Retrieved 20 September 2019.
cite-note-1010. ↑ citerefporter2013Porter, Brett (18 July 2013). "Apache C++ Standard Library and the Attic". stdcxx-dev mailing list. Archived from the original on 23 July 2013. Retrieved 27 February 2014.
cite-note-p2465r3-1111. ↑ C++ Standards Committee. (2022). P2465R3 - C++ Modules: Design and Evolution. Retrieved from https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2465r3.pdf Archived 18 November 2022 at the Wayback Machine
cite-note-1212. ↑ "Standard C++ modules".
cite-note-p0581r1-1313. ↑ C++ Standards Committee. (2018). P0581R1 - Modules for C++. Retrieved from https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0581r1.pdf
cite-note-p2412r0-1414. ↑ C++ Standards Committee. (2021). P2412R0 - Further refinements to the C++ Modules Design. Retrieved from https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2412r0.pdf Archived 20 November 2024 at the Wayback Machine
cite-note-151. citereffilipekFilipek, Bartlomiej. "Polymorphic Allocators, std::vector Growth and Hacking". Archived from the original on 29 June 2020. Retrieved 30 April 2021.
cite-note-162. "Working Draft, Standard for Programming Language C++" (PDF). open-std.org. ISO/IEC. 1 April 2020. p. 492. Archived (PDF) from the original on 27 April 2020. Retrieved 30 April 2021.

Further reading

• citerefstroustrup2013Stroustrup, Bjarne (2013). The C++ Programming Language. Addison-Wesley. ISBN 978-0321563842.
• citerefjosuttis2012Josuttis, Nicolai (2012). The C++ Standard Library – A Tutorial and Reference. Addison-Wesley. ISBN 978-0-321-62321-8.
• citerefvan-weertgregoire2016Van Weert, Peter; Gregoire, Marc (14 June 2016). C++ Standard Library Quick Reference. Apress. ISBN 978-1484218754. Archived from the original on 16 May 2021. Retrieved 24 March 2017.

External links

• C++ Standard Library reference
• Microsoft C++ Standard Library Reference
• Rogue Wave SourcePro C++ documentation
• Apache C++ Standard Library Wiki, retired 15 May 2014 (based on Rogue Wave C++ Standard Library 4.1.0)
• STLport C++ Standard Library documentation
• The GNU C++ Library online documentation
• LLVM/Clang C++ Standard Library documentation